package me.monster.smarttraffic.base;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import butterknife.ButterKnife;
import me.monster.smarttraffic.tool.ToastUtils;

/**
 * @description
 * @author: Created jiangjiwei in 2020-02-10 19:21
 */
public abstract class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (behindStatusBar()) {
            beautifulStatusBar();
        }
        if (hideNavigation()) {
            hideNavigationBar();
        }
        setContentView(getLayoutId());
        ButterKnife.bind(this);
    }

    private boolean hideNavigation() {
        return false;
    }

    private boolean behindStatusBar() {
        return true;
    }

    public void toast(CharSequence msg) {
        ToastUtils.getInstance().toast(msg);
    }

    public void toast(int resId) {
        toast(getString(resId));
    }

    private void beautifulStatusBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
    }

    private void hideNavigationBar() {
        View decorView = getWindow().getDecorView();
        int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(option);
    }

    /**
     * 获取布局文件
     *
     * @return 布局文件 id
     */
    public abstract int getLayoutId();
}
